package lily.phs.pregnance;

import lily.phs.object.HereTipa;
import lily.phs.object.PrenatalVisit;
import lily.phs.urh.R;
import lily.ui.control.MyPopupWindow;


import android.content.Context;
import android.text.InputType;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;

/**
 * 第2~5次产前访视记录表：界面布局和数据处理
 * @author heckassitant
 *
 */
public class PrenatalVisitView extends LinearLayout implements OnClickListener, OnFocusChangeListener{

	private MyPopupWindow mPopupWindow;
	private Context mContext;
	private int profileid=0;
	
	private EditText et_name,et_id,et_date_2,et_date_3,et_date_4,et_date_5,et_preg_week_2,et_preg_week_3,et_preg_week_4,et_preg_week_5,
	                 et_selftalk_2,et_selftalk_3,et_selftalk_4,et_selftalk_5,et_weight_2,et_weight_3,et_weight_4,et_weight_5,
	                 et_palace_height_2,et_palace_height_3,et_palace_height_4,et_palace_height_5,et_chest_measure_2,et_chest_measure_3,
	                 et_chest_measure_4,et_chest_measure_5,et_fetal_position_2,et_fetal_position_3,et_fetal_position_4,et_fetal_position_5,
	                 et_fetal_heartrate_2,et_fetal_heartrate_3,et_fetal_heartrate_4,et_fetal_heartrate_5,et_bloodpressure_high_2,
	                 et_bloodpressure_high_3,et_bloodpressure_high_4,et_bloodpressure_high_5,et_bloodpressure_low_2,et_bloodpressure_low_3,
	                 et_bloodpressure_low_4,et_bloodpressure_low_5,et_hgb_2,et_hgb_3,et_hgb_4,et_hgb_5,et_urine_protein_2,et_urine_protein_3,
	                 et_urine_protein_4,et_urine_protein_5,et_other_assitest_2,et_other_assitest_3,et_other_assitest_4,et_other_assitest_5,
	                 et_abnormal_2,et_abnormal_3,et_abnormal_4,et_abnormal_5,
	                 et_guide_2_other,et_guide_3_other,et_guide_4_other,et_guide_5_other,et_transfer_reason_2,et_transfer_reason_3,
	                 et_transfer_reason_4,et_transfer_reason_5,et_transfer_hospital_2,et_transfer_hospital_3,et_transfer_hospital_4,et_transfer_hospital_5,
	                 et_next_visit_date_2,et_next_visit_date_3,et_next_visit_date_4,et_next_visit_date_5,et_doctor_2,et_doctor_3,et_doctor_4,et_doctor_5;
	private RadioGroup rgIsAbnormal_2,rgIsAbnormal_3,rgIsAbnormal_4,rgIsAbnormal_5,rgNeedTransfer_2,rgNeedTransfer_3,rgNeedTransfer_4,rgNeedTransfer_5;
	private RadioButton rb_is_abnormal_no_2,rb_is_abnormal_no_3,rb_is_abnormal_no_4,rb_is_abnormal_no_5,rb_is_abnormal_yes_2,
	                    rb_is_abnormal_yes_3,rb_is_abnormal_yes_4,rb_is_abnormal_yes_5,rb_need_transfer_no_2,rb_need_transfer_no_3,rb_need_transfer_no_4,rb_need_transfer_no_5,
	                    rb_need_transfer_yes_2,rb_need_transfer_yes_3,rb_need_transfer_yes_4,rb_need_transfer_yes_5;
	
	private CheckBox cb_guide_2_1,cb_guide_2_2,cb_guide_2_3,cb_guide_2_4,cb_guide_2_5,cb_guide_3_1,cb_guide_3_2,cb_guide_3_3,cb_guide_3_4,
	                 cb_guide_3_5,cb_guide_3_6,cb_guide_3_7,cb_guide_4_1,cb_guide_4_2,cb_guide_4_3,cb_guide_4_4,cb_guide_4_5,cb_guide_4_6,cb_guide_4_7,
	                 cb_guide_4_8,cb_guide_5_1,cb_guide_5_2,cb_guide_5_3,cb_guide_5_4,cb_guide_5_5,cb_guide_5_6,cb_guide_5_7,cb_guide_5_8;
	
	private PrenatalVisit pv;
	private View child;
	private HereTipa ht;
	
	public PrenatalVisitView(Context context,int profileId) {
		super(context);
		// TODO Auto-generated constructor stub
		this.profileid = profileId;
		this.mContext = context;
		final LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		child = inflater.inflate(R.layout.tablepreg2, null);
	}

	/**
	 * 初始化views
	 */
	public void initViews() {
		// TODO Auto-generated method stub
		initialState();
		
		String temp = "";
		int itemp=-1;
		float ftemp=-1f;
		
		temp = ht.getHeti_name();
		et_name.setText(temp);
		et_name.setEnabled(false);
		temp = ht.getHeti_here_id();
		et_id.setText(temp);
		et_id.setEnabled(false);
		
		//second time
//		pv.setPrvi_id(this.profileid);
//		pv.setPrvi_times(2);
//		pv.selectPrenatalVisit(this.profileid, 2);
		temp = pv.getPrvi_date();
		et_date_2.setText(temp);
		itemp = pv.getPrvi_preg_week();
		if(itemp!=-1){
			et_preg_week_2.setText(String.valueOf(itemp));
		}
		temp = pv.getPrvi_selftalk();
		et_selftalk_2.setText(temp);
		ftemp = pv.getPrvi_weight();
		if(ftemp!=-1f){
			et_weight_2.setText(String.valueOf(ftemp));
		}
		itemp = pv.getPrvi_palace_height();
		if(itemp!=-1){
			et_palace_height_2.setText(String.valueOf(itemp));
		}
		itemp = pv.getPrvi_chest_measure();
		if(itemp!=-1){
			et_chest_measure_2.setText(String.valueOf(itemp));
		}
		temp = pv.getPrvi_fetal_position();
		et_fetal_position_2.setText(temp);
		itemp = pv.getPrvi_fetal_heartrate();
		if(itemp!=-1){
			et_fetal_heartrate_2.setText(String.valueOf(itemp));
		}
		
		itemp = pv.getPrvi_bloodpressure_high();
		if(itemp!=-1){
			et_bloodpressure_high_2.setText(String.valueOf(itemp));
		}
		itemp = pv.getPrvi_bloodpressure_low();
		if(itemp!=-1){
			et_bloodpressure_low_2.setText(String.valueOf(itemp));
		}
		ftemp = pv.getPrvi_hgb();
		if(ftemp!=-1f){
			et_hgb_2.setText(String.valueOf(ftemp));
		}
		ftemp = pv.getPrvi_urine_protein();
		if(ftemp!=-1f){
			et_urine_protein_2.setText(String.valueOf(ftemp));
		}
		temp = pv.getPrvi_other_assitest();
		et_other_assitest_2.setText(temp);
		
		itemp = pv.getPrvi_is_abnormal();
		switch(itemp){
		case 1:
			rgIsAbnormal_2.check(0);
			rb_is_abnormal_no_2.setChecked(true);
			break;
		case 2:{
			rgIsAbnormal_2.check(1);
			rb_is_abnormal_yes_2.setChecked(true);
			temp = pv.getPrvi_abnormal();
			et_abnormal_2.setText(temp);
		}
		}
		
		temp = pv.getPrvi_guide();
		if(temp.length()>0){
			String[] ss = temp.split(",");
			for(int i=0;i<ss.length;i++){
				int k = Integer.parseInt(ss[i]);
				switch(k){
				case 1:
					cb_guide_2_1.setChecked(true);
					break;
				case 2:
					cb_guide_2_2.setChecked(true);
					break;
				case 3:
					cb_guide_2_3.setChecked(true);
					break;
				case 4:
					cb_guide_2_4.setChecked(true);
					break;
				case 5:{
					cb_guide_2_5.setChecked(true);
					temp = pv.getPrvi_other_guide();
					et_guide_2_other.setText(temp);
					break;
				}
				}
			}
		}
		
		itemp = pv.getPrvi_need_transfer();
		switch(itemp){
		case 1:
			rgNeedTransfer_2.check(0);
			rb_need_transfer_no_2.setChecked(true);
			break;
		case 2:{
			rgNeedTransfer_2.check(1);
			rb_need_transfer_yes_2.setChecked(true);
			temp = pv.getPrvi_transfer_reason();
			et_transfer_reason_2.setText(temp);
			temp = pv.getPrvi_transfer_hospital();
			et_transfer_hospital_2.setText(temp);
			break;
		}
		}
		
		temp = pv.getPrvi_next_visit_date();
		et_next_visit_date_2.setText(temp);
		temp = pv.getPrvi_doctor();
		et_doctor_2.setText(temp);
		
		//third time
		pv.setPrvi_id(this.profileid);
		pv.setPrvi_times(3);
		pv.selectPrenatalVisit(this.profileid, 3);
		temp = pv.getPrvi_date();
		et_date_3.setText(temp);
		itemp = pv.getPrvi_preg_week();
		if(itemp!=-1){
			et_preg_week_3.setText(String.valueOf(itemp));
		}
		temp = pv.getPrvi_selftalk();
		et_selftalk_3.setText(temp);
		ftemp = pv.getPrvi_weight();
		if(ftemp!=-1f){
			et_weight_3.setText(String.valueOf(ftemp));
		}
		itemp = pv.getPrvi_palace_height();
		if(itemp!=-1){
			et_palace_height_3.setText(String.valueOf(itemp));
		}
		itemp = pv.getPrvi_chest_measure();
		if(itemp!=-1){
			et_chest_measure_3.setText(String.valueOf(itemp));
		}
		temp = pv.getPrvi_fetal_position();
		et_fetal_position_3.setText(temp);
		itemp = pv.getPrvi_fetal_heartrate();
		if(itemp!=-1){
			et_fetal_heartrate_3.setText(String.valueOf(itemp));
		}
		
		itemp = pv.getPrvi_bloodpressure_high();
		if(itemp!=-1){
			et_bloodpressure_high_3.setText(String.valueOf(itemp));
		}
		itemp = pv.getPrvi_bloodpressure_low();
		if(itemp!=-1){
			et_bloodpressure_low_3.setText(String.valueOf(itemp));
		}
		ftemp = pv.getPrvi_hgb();
		if(ftemp!=-1f){
			et_hgb_3.setText(String.valueOf(ftemp));
		}
		ftemp = pv.getPrvi_urine_protein();
		if(ftemp!=-1f){
			et_urine_protein_3.setText(String.valueOf(ftemp));
		}
		temp = pv.getPrvi_other_assitest();
		et_other_assitest_3.setText(temp);
		
		itemp = pv.getPrvi_is_abnormal();
		switch(itemp){
		case 1:
			rgIsAbnormal_3.check(0);
			rb_is_abnormal_no_3.setChecked(true);
			break;
		case 2:{
			rgIsAbnormal_3.check(1);
			rb_is_abnormal_yes_3.setChecked(true);
			temp = pv.getPrvi_abnormal();
			et_abnormal_3.setText(temp);
		}
		}
		
		temp = pv.getPrvi_guide();
		if(temp.length()>0){
			String[] ss = temp.split(",");
			for(int i=0;i<ss.length;i++){
				int k = Integer.parseInt(ss[i]);
				switch(k){
				case 1:
					cb_guide_3_1.setChecked(true);
					break;
				case 2:
					cb_guide_3_2.setChecked(true);
					break;
				case 3:
					cb_guide_3_3.setChecked(true);
					break;
				case 4:
					cb_guide_3_4.setChecked(true);
					break;
				case 5:
					cb_guide_3_5.setChecked(true);
					break;
				case 6:
					cb_guide_3_6.setChecked(true);
					break;
				case 7:{
					cb_guide_3_7.setChecked(true);
					temp = pv.getPrvi_other_guide();
					et_guide_3_other.setText(temp);
					break;
				}
				}
			}
		}
		
		itemp = pv.getPrvi_need_transfer();
		switch(itemp){
		case 1:
			rgNeedTransfer_3.check(0);
			rb_need_transfer_no_3.setChecked(true);
			break;
		case 2:{
			rgNeedTransfer_3.check(1);
			rb_need_transfer_yes_3.setChecked(true);
			temp = pv.getPrvi_transfer_reason();
			et_transfer_reason_3.setText(temp);
			temp = pv.getPrvi_transfer_hospital();
			et_transfer_hospital_3.setText(temp);
			break;
		}
		}
		
		temp = pv.getPrvi_next_visit_date();
		et_next_visit_date_3.setText(temp);
		temp = pv.getPrvi_doctor();
		et_doctor_3.setText(temp);
		
		//forth time*
		pv.setPrvi_id(this.profileid);
		pv.setPrvi_times(4);
		pv.selectPrenatalVisit(this.profileid, 4);
		temp = pv.getPrvi_date();
		et_date_4.setText(temp);
		itemp = pv.getPrvi_preg_week();
		if(itemp!=-1){
			et_preg_week_4.setText(String.valueOf(itemp));
		}
		temp = pv.getPrvi_selftalk();
		et_selftalk_4.setText(temp);
		ftemp = pv.getPrvi_weight();
		if(ftemp!=-1f){
			et_weight_4.setText(String.valueOf(ftemp));
		}
		itemp = pv.getPrvi_palace_height();
		if(itemp!=-1){
			et_palace_height_4.setText(String.valueOf(itemp));
		}
		itemp = pv.getPrvi_chest_measure();
		if(itemp!=-1){
			et_chest_measure_4.setText(String.valueOf(itemp));
		}
		temp = pv.getPrvi_fetal_position();
		et_fetal_position_4.setText(temp);
		itemp = pv.getPrvi_fetal_heartrate();
		if(itemp!=-1){
			et_fetal_heartrate_4.setText(String.valueOf(itemp));
		}
		
		itemp = pv.getPrvi_bloodpressure_high();
		if(itemp!=-1){
			et_bloodpressure_high_4.setText(String.valueOf(itemp));
		}
		itemp = pv.getPrvi_bloodpressure_low();
		if(itemp!=-1){
			et_bloodpressure_low_4.setText(String.valueOf(itemp));
		}
		ftemp = pv.getPrvi_hgb();
		if(ftemp!=-1f){
			et_hgb_4.setText(String.valueOf(ftemp));
		}
		ftemp = pv.getPrvi_urine_protein();
		if(ftemp!=-1f){
			et_urine_protein_4.setText(String.valueOf(ftemp));
		}
		temp = pv.getPrvi_other_assitest();
		et_other_assitest_4.setText(temp);
		
		itemp = pv.getPrvi_is_abnormal();
		switch(itemp){
		case 1:
			rgIsAbnormal_4.check(0);
			rb_is_abnormal_no_4.setChecked(true);
			break;
		case 2:{
			rgIsAbnormal_4.check(1);
			rb_is_abnormal_yes_4.setChecked(true);
			temp = pv.getPrvi_abnormal();
			et_abnormal_4.setText(temp);
		}
		}
		
		temp = pv.getPrvi_guide();
		if(temp.length()>0){
			String[] ss = temp.split(",");
			for(int i=0;i<ss.length;i++){
				int k = Integer.parseInt(ss[i]);
				switch(k){
				case 1:
					cb_guide_4_1.setChecked(true);
					break;
				case 2:
					cb_guide_4_2.setChecked(true);
					break;
				case 3:
					cb_guide_4_3.setChecked(true);
					break;
				case 4:
					cb_guide_4_4.setChecked(true);
					break;
				case 5:
					cb_guide_4_5.setChecked(true);
					break;
				case 6:
					cb_guide_4_6.setChecked(true);
					break;
				case 7:
					cb_guide_4_7.setChecked(true);
					break;
				case 8:{
					cb_guide_4_8.setChecked(true);
					temp = pv.getPrvi_other_guide();
					et_guide_4_other.setText(temp);
					break;
				}
				}
			}
		}
		
		itemp = pv.getPrvi_need_transfer();
		switch(itemp){
		case 1:
			rgNeedTransfer_4.check(0);
			rb_need_transfer_no_4.setChecked(true);
			break;
		case 2:{
			rgNeedTransfer_4.check(1);
			rb_need_transfer_yes_4.setChecked(true);
			temp = pv.getPrvi_transfer_reason();
			et_transfer_reason_4.setText(temp);
			temp = pv.getPrvi_transfer_hospital();
			et_transfer_hospital_4.setText(temp);
			break;
		}
		}
		
		temp = pv.getPrvi_next_visit_date();
		et_next_visit_date_4.setText(temp);
		temp = pv.getPrvi_doctor();
		et_doctor_4.setText(temp);
		
		//fifth time
		pv.setPrvi_id(this.profileid);
		pv.setPrvi_times(5);
		pv.selectPrenatalVisit(this.profileid, 5);
		temp = pv.getPrvi_date();
		et_date_5.setText(temp);
		itemp = pv.getPrvi_preg_week();
		if(itemp!=-1){
			et_preg_week_5.setText(String.valueOf(itemp));
		}
		temp = pv.getPrvi_selftalk();
		et_selftalk_5.setText(temp);
		ftemp = pv.getPrvi_weight();
		if(ftemp!=-1f){
			et_weight_5.setText(String.valueOf(ftemp));
		}
		itemp = pv.getPrvi_palace_height();
		if(itemp!=-1){
			et_palace_height_5.setText(String.valueOf(itemp));
		}
		itemp = pv.getPrvi_chest_measure();
		if(itemp!=-1){
			et_chest_measure_5.setText(String.valueOf(itemp));
		}
		temp = pv.getPrvi_fetal_position();
		et_fetal_position_5.setText(temp);
		itemp = pv.getPrvi_fetal_heartrate();
		if(itemp!=-1){
			et_fetal_heartrate_5.setText(String.valueOf(itemp));
		}
		
		itemp = pv.getPrvi_bloodpressure_high();
		if(itemp!=-1){
			et_bloodpressure_high_5.setText(String.valueOf(itemp));
		}
		itemp = pv.getPrvi_bloodpressure_low();
		if(itemp!=-1){
			et_bloodpressure_low_5.setText(String.valueOf(itemp));
		}
		ftemp = pv.getPrvi_hgb();
		if(ftemp!=-1f){
			et_hgb_5.setText(String.valueOf(ftemp));
		}
		ftemp = pv.getPrvi_urine_protein();
		if(ftemp!=-1f){
			et_urine_protein_5.setText(String.valueOf(ftemp));
		}
		temp = pv.getPrvi_other_assitest();
		et_other_assitest_5.setText(temp);
		
		itemp = pv.getPrvi_is_abnormal();
		switch(itemp){
		case 1:
			rgIsAbnormal_5.check(0);
			rb_is_abnormal_no_5.setChecked(true);
			break;
		case 2:{
			rgIsAbnormal_5.check(1);
			rb_is_abnormal_yes_5.setChecked(true);
			temp = pv.getPrvi_abnormal();
			et_abnormal_5.setText(temp);
		}
		}
		
		temp = pv.getPrvi_guide();
		if(temp.length()>0){
			String[] ss = temp.split(",");
			for(int i=0;i<ss.length;i++){
				int k = Integer.parseInt(ss[i]);
				switch(k){
				case 1:
					cb_guide_5_1.setChecked(true);
					break;
				case 2:
					cb_guide_5_2.setChecked(true);
					break;
				case 3:
					cb_guide_5_3.setChecked(true);
					break;
				case 4:
					cb_guide_5_4.setChecked(true);
					break;
				case 5:
					cb_guide_5_5.setChecked(true);
					break;
				case 6:
					cb_guide_5_6.setChecked(true);
					break;
				case 7:
					cb_guide_5_7.setChecked(true);
					break;
				case 8:{
					cb_guide_5_8.setChecked(true);
					temp = pv.getPrvi_other_guide();
					et_guide_5_other.setText(temp);
					break;
				}
				}
			}
		}
		
		itemp = pv.getPrvi_need_transfer();
		switch(itemp){
		case 1:
			rgNeedTransfer_5.check(0);
			rb_need_transfer_no_5.setChecked(true);
			break;
		case 2:{
			rgNeedTransfer_5.check(1);
			rb_need_transfer_yes_5.setChecked(true);
			temp = pv.getPrvi_transfer_reason();
			et_transfer_reason_5.setText(temp);
			temp = pv.getPrvi_transfer_hospital();
			et_transfer_hospital_5.setText(temp);
			break;
		}
		}
		
		temp = pv.getPrvi_next_visit_date();
		et_next_visit_date_5.setText(temp);
		temp = pv.getPrvi_doctor();
		et_doctor_5.setText(temp);
		
	}

	/**
	 * 初始时：横线为空，所有选择项未选中
	 */
	private void initialState() {
		// TODO Auto-generated method stub
		et_name.setText("");
		et_id.setText("");
		et_date_2.setText("");
		et_date_3.setText("");
		et_date_4.setText("");
		et_date_5.setText("");
		et_preg_week_2.setText("");
		et_preg_week_3.setText("");
		et_preg_week_4.setText("");
		et_preg_week_5.setText("");
        et_selftalk_2.setText("");
        et_selftalk_3.setText("");
        et_selftalk_4.setText("");
        et_selftalk_5.setText("");
        et_weight_2.setText("");
        et_weight_3.setText("");
        et_weight_4.setText("");
        et_weight_5.setText("");
        et_palace_height_2.setText("");
        et_palace_height_3.setText("");
        et_palace_height_4.setText("");
        et_palace_height_5.setText("");
        et_chest_measure_2.setText("");
        et_chest_measure_3.setText("");
        et_chest_measure_4.setText("");
        et_chest_measure_5.setText("");
        et_fetal_position_2.setText("");
        et_fetal_position_3.setText("");
        et_fetal_position_4.setText("");
        et_fetal_position_5.setText("");
        et_fetal_heartrate_2.setText("");
        et_fetal_heartrate_3.setText("");
        et_fetal_heartrate_4.setText("");
        et_fetal_heartrate_5.setText("");
        et_bloodpressure_high_2.setText("");
        et_bloodpressure_high_3.setText("");
        et_bloodpressure_high_4.setText("");
        et_bloodpressure_high_5.setText("");
        et_bloodpressure_low_2.setText("");
        et_bloodpressure_low_3.setText("");
        et_bloodpressure_low_4.setText("");
        et_bloodpressure_low_5.setText("");
        et_hgb_2.setText("");
        et_hgb_3.setText("");
        et_hgb_4.setText("");
        et_hgb_5.setText("");
        et_urine_protein_2.setText("");
        et_urine_protein_3.setText("");
        et_urine_protein_4.setText("");
        et_urine_protein_5.setText("");
        et_other_assitest_2.setText("");
        et_other_assitest_3.setText("");
        et_other_assitest_4.setText("");
        et_other_assitest_5.setText("");
        et_abnormal_2.setText("");
        et_abnormal_3.setText("");
        et_abnormal_4.setText("");
        et_abnormal_5.setText("");
        et_guide_2_other.setText("");
        et_guide_3_other.setText("");
        et_guide_4_other.setText("");
        et_guide_5_other.setText("");
        et_transfer_reason_2.setText("");
        et_transfer_reason_3.setText("");
        et_transfer_reason_4.setText("");
        et_transfer_reason_5.setText("");
        et_transfer_hospital_2.setText("");
        et_transfer_hospital_3.setText("");
        et_transfer_hospital_4.setText("");
        et_transfer_hospital_5.setText("");
        et_next_visit_date_2.setText("");
        et_next_visit_date_3.setText("");
        et_next_visit_date_4.setText("");
        et_next_visit_date_5.setText("");
        et_doctor_2.setText("");
        et_doctor_3.setText("");
        et_doctor_4.setText("");
        et_doctor_5.setText("");
		rb_is_abnormal_no_2.setChecked(false);
		rb_is_abnormal_no_3.setChecked(false);
		rb_is_abnormal_no_4.setChecked(false);
		rb_is_abnormal_no_5.setChecked(false);
		rb_is_abnormal_yes_2.setChecked(false);
		rb_is_abnormal_yes_3.setChecked(false);
		rb_is_abnormal_yes_4.setChecked(false);
		rb_is_abnormal_yes_5.setChecked(false);
		rb_need_transfer_no_2.setChecked(false);
		rb_need_transfer_no_3.setChecked(false);
		rb_need_transfer_no_4.setChecked(false);
		rb_need_transfer_no_5.setChecked(false);
        rb_need_transfer_yes_2.setChecked(false);
        rb_need_transfer_yes_3.setChecked(false);
        rb_need_transfer_yes_4.setChecked(false);
        rb_need_transfer_yes_5.setChecked(false);
		cb_guide_2_1.setChecked(false);
		cb_guide_2_2.setChecked(false);
		cb_guide_2_3.setChecked(false);
		cb_guide_2_4.setChecked(false);
		cb_guide_2_5.setChecked(false);
		cb_guide_3_1.setChecked(false);
		cb_guide_3_2.setChecked(false);
		cb_guide_3_3.setChecked(false);
		cb_guide_3_4.setChecked(false);
        cb_guide_3_5.setChecked(false);
        cb_guide_3_6.setChecked(false);
        cb_guide_3_7.setChecked(false);
        cb_guide_4_1.setChecked(false);
        cb_guide_4_2.setChecked(false);
        cb_guide_4_3.setChecked(false);
        cb_guide_4_4.setChecked(false);
        cb_guide_4_5.setChecked(false);
        cb_guide_4_6.setChecked(false);
        cb_guide_4_7.setChecked(false);
        cb_guide_4_8.setChecked(false);
        cb_guide_5_1.setChecked(false);
        cb_guide_5_2.setChecked(false);
        cb_guide_5_3.setChecked(false);
        cb_guide_5_4.setChecked(false);
        cb_guide_5_5.setChecked(false);
        cb_guide_5_6.setChecked(false);
        cb_guide_5_7.setChecked(false);
        cb_guide_5_8.setChecked(false);
		
	}

	/**
	 * 与xml文件关联
	 */
	public void findViewsById() {
		// TODO Auto-generated method stub
		et_name = (EditText)child.findViewById(R.id.pre_name);
		et_id = (EditText)child.findViewById(R.id.pre_id);
		et_date_2 = (EditText)child.findViewById(R.id.pre_date_2);
		et_date_2.setInputType(InputType.TYPE_NULL);
		et_date_2.setOnClickListener(this);
		et_date_2.setOnFocusChangeListener(this);
		et_date_3 = (EditText)child.findViewById(R.id.pre_date_3);
		et_date_3.setInputType(InputType.TYPE_NULL);
		et_date_3.setOnClickListener(this);
		et_date_3.setOnFocusChangeListener(this);
		et_date_4 = (EditText)child.findViewById(R.id.pre_date_4);
		et_date_4.setInputType(InputType.TYPE_NULL);
		et_date_4.setOnClickListener(this);
		et_date_4.setOnFocusChangeListener(this);
		et_date_5 = (EditText)child.findViewById(R.id.pre_date_5);
		et_date_5.setInputType(InputType.TYPE_NULL);
		et_date_5.setOnClickListener(this);
		et_date_5.setOnFocusChangeListener(this);
		et_preg_week_2 = (EditText)child.findViewById(R.id.pre_preg_week_2);
		et_preg_week_3 = (EditText)child.findViewById(R.id.pre_preg_week_3);
		et_preg_week_4 = (EditText)child.findViewById(R.id.pre_preg_week_4);
		et_preg_week_5 = (EditText)child.findViewById(R.id.pre_preg_week_5);
        et_selftalk_2 = (EditText)child.findViewById(R.id.pre_selftalk_2);
        et_selftalk_3 = (EditText)child.findViewById(R.id.pre_selftalk_3);
        et_selftalk_4 = (EditText)child.findViewById(R.id.pre_selftalk_4);
        et_selftalk_5 = (EditText)child.findViewById(R.id.pre_selftalk_5);
        et_weight_2 = (EditText)child.findViewById(R.id.pre_weight_2);
        et_weight_3 = (EditText)child.findViewById(R.id.pre_weight_3);
        et_weight_4 = (EditText)child.findViewById(R.id.pre_weight_4);
        et_weight_5 = (EditText)child.findViewById(R.id.pre_weight_5);
        et_palace_height_2 = (EditText)child.findViewById(R.id.pre_palace_height_2);
        et_palace_height_3 = (EditText)child.findViewById(R.id.pre_palace_height_3);
        et_palace_height_4 = (EditText)child.findViewById(R.id.pre_palace_height_4);
        et_palace_height_5 = (EditText)child.findViewById(R.id.pre_palace_height_5);
        et_chest_measure_2 = (EditText)child.findViewById(R.id.pre_chest_measure_2);
        et_chest_measure_3 = (EditText)child.findViewById(R.id.pre_chest_measure_3);
        et_chest_measure_4 = (EditText)child.findViewById(R.id.pre_chest_measure_4);
        et_chest_measure_5 = (EditText)child.findViewById(R.id.pre_chest_measure_5);
        et_fetal_position_2 = (EditText)child.findViewById(R.id.pre_fetal_position_2);
        et_fetal_position_3 = (EditText)child.findViewById(R.id.pre_fetal_position_3);
        et_fetal_position_4 = (EditText)child.findViewById(R.id.pre_fetal_position_4);
        et_fetal_position_5 = (EditText)child.findViewById(R.id.pre_fetal_position_5);
        et_fetal_heartrate_2 = (EditText)child.findViewById(R.id.pre_fetal_heartrate_2);
        et_fetal_heartrate_3 = (EditText)child.findViewById(R.id.pre_fetal_heartrate_3);
        et_fetal_heartrate_4 = (EditText)child.findViewById(R.id.pre_fetal_heartrate_4);
        et_fetal_heartrate_5 = (EditText)child.findViewById(R.id.pre_fetal_heartrate_5);
        et_bloodpressure_high_2 = (EditText)child.findViewById(R.id.pre_bloodpressure_high_2);
        et_bloodpressure_high_3 = (EditText)child.findViewById(R.id.pre_bloodpressure_high_3);
        et_bloodpressure_high_4 = (EditText)child.findViewById(R.id.pre_bloodpressure_high_4);
        et_bloodpressure_high_5 = (EditText)child.findViewById(R.id.pre_bloodpressure_high_5);
        et_bloodpressure_low_2 = (EditText)child.findViewById(R.id.pre_bloodpressure_low_2);
        et_bloodpressure_low_3 = (EditText)child.findViewById(R.id.pre_bloodpressure_low_3);
        et_bloodpressure_low_4 = (EditText)child.findViewById(R.id.pre_bloodpressure_low_4);
        et_bloodpressure_low_5 = (EditText)child.findViewById(R.id.pre_bloodpressure_low_5);
        et_hgb_2 = (EditText)child.findViewById(R.id.pre_hgb_2);
        et_hgb_3 = (EditText)child.findViewById(R.id.pre_hgb_3);
        et_hgb_4 = (EditText)child.findViewById(R.id.pre_hgb_4);
        et_hgb_5 = (EditText)child.findViewById(R.id.pre_hgb_5);
        et_urine_protein_2 = (EditText)child.findViewById(R.id.pre_urine_protein_2);
        et_urine_protein_3 = (EditText)child.findViewById(R.id.pre_urine_protein_3);
        et_urine_protein_4 = (EditText)child.findViewById(R.id.pre_urine_protein_4);
        et_urine_protein_5 = (EditText)child.findViewById(R.id.pre_urine_protein_5);
        et_other_assitest_2 = (EditText)child.findViewById(R.id.pre_other_assitest_2);
        et_other_assitest_3 = (EditText)child.findViewById(R.id.pre_other_assitest_3);
        et_other_assitest_4 = (EditText)child.findViewById(R.id.pre_other_assitest_4);
        et_other_assitest_5 = (EditText)child.findViewById(R.id.pre_other_assitest_5);
        et_abnormal_2 = (EditText)child.findViewById(R.id.pre_abnormal_2);
        et_abnormal_2.setOnFocusChangeListener(this);
        et_abnormal_2.setOnClickListener(this);
        et_abnormal_3 = (EditText)child.findViewById(R.id.pre_abnormal_3);
        et_abnormal_3.setOnFocusChangeListener(this);
        et_abnormal_3.setOnClickListener(this);
        et_abnormal_4 = (EditText)child.findViewById(R.id.pre_abnormal_4);
        et_abnormal_4.setOnFocusChangeListener(this);
        et_abnormal_4.setOnClickListener(this);
        et_abnormal_5 = (EditText)child.findViewById(R.id.pre_abnormal_5);
        et_abnormal_5.setOnFocusChangeListener(this);
        et_abnormal_5.setOnClickListener(this);
        et_guide_2_other = (EditText)child.findViewById(R.id.pre_guide_2_other);
        et_guide_2_other.setOnFocusChangeListener(this);
        et_guide_2_other.setOnClickListener(this);
        et_guide_3_other = (EditText)child.findViewById(R.id.pre_guide_3_other);
        et_guide_3_other.setOnFocusChangeListener(this);
        et_guide_3_other.setOnClickListener(this);
        et_guide_4_other = (EditText)child.findViewById(R.id.pre_guide_4_other);
        et_guide_4_other.setOnFocusChangeListener(this);
        et_guide_4_other.setOnClickListener(this);
        et_guide_5_other = (EditText)child.findViewById(R.id.pre_guide_5_other);
        et_guide_5_other.setOnFocusChangeListener(this);
        et_guide_5_other.setOnClickListener(this);
        et_transfer_reason_2 = (EditText)child.findViewById(R.id.pre_transfer_reason_2);
        et_transfer_reason_2.setOnFocusChangeListener(this);
        et_transfer_reason_2.setOnClickListener(this);
        et_transfer_reason_3 = (EditText)child.findViewById(R.id.pre_transfer_reason_3);
        et_transfer_reason_3.setOnFocusChangeListener(this);
        et_transfer_reason_3.setOnClickListener(this);
        et_transfer_reason_4 = (EditText)child.findViewById(R.id.pre_transfer_reason_4);
        et_transfer_reason_4.setOnFocusChangeListener(this);
        et_transfer_reason_4.setOnClickListener(this);
        et_transfer_reason_5 = (EditText)child.findViewById(R.id.pre_transfer_reason_5);
        et_transfer_reason_5.setOnFocusChangeListener(this);
        et_transfer_reason_5.setOnClickListener(this);
        et_transfer_hospital_2 = (EditText)child.findViewById(R.id.pre_transfer_hospital_2);
        et_transfer_hospital_2.setOnFocusChangeListener(this);
        et_transfer_hospital_2.setOnClickListener(this);
        et_transfer_hospital_3 = (EditText)child.findViewById(R.id.pre_transfer_hospital_3);
        et_transfer_hospital_3.setOnFocusChangeListener(this);
        et_transfer_hospital_3.setOnClickListener(this);
        et_transfer_hospital_4 = (EditText)child.findViewById(R.id.pre_transfer_hospital_4);
        et_transfer_hospital_4.setOnFocusChangeListener(this);
        et_transfer_hospital_4.setOnClickListener(this);
        et_transfer_hospital_5 = (EditText)child.findViewById(R.id.pre_transfer_hospital_5);
        et_transfer_hospital_5.setOnFocusChangeListener(this);
        et_transfer_hospital_5.setOnClickListener(this);
        et_next_visit_date_2 = (EditText)child.findViewById(R.id.pre_next_visit_date_2);
        et_next_visit_date_2.setInputType(InputType.TYPE_NULL);
        et_next_visit_date_2.setOnClickListener(this);
        et_next_visit_date_2.setOnFocusChangeListener(this);
        et_next_visit_date_3 = (EditText)child.findViewById(R.id.pre_next_visit_date_3);
        et_next_visit_date_3.setInputType(InputType.TYPE_NULL);
		et_next_visit_date_3.setOnClickListener(this);
		et_next_visit_date_3.setOnFocusChangeListener(this);
        et_next_visit_date_4 = (EditText)child.findViewById(R.id.pre_next_visit_date_4);
        et_next_visit_date_4.setInputType(InputType.TYPE_NULL);
        et_next_visit_date_4.setOnClickListener(this);
        et_next_visit_date_4.setOnFocusChangeListener(this);
        et_next_visit_date_5 = (EditText)child.findViewById(R.id.pre_next_visit_date_5);
        et_next_visit_date_5.setInputType(InputType.TYPE_NULL);
        et_next_visit_date_5.setOnClickListener(this);
        et_next_visit_date_5.setOnFocusChangeListener(this);
        et_doctor_2 = (EditText)child.findViewById(R.id.pre_doctor_2);
        et_doctor_3 = (EditText)child.findViewById(R.id.pre_doctor_3);
        et_doctor_4 = (EditText)child.findViewById(R.id.pre_doctor_4);
        et_doctor_5 = (EditText)child.findViewById(R.id.pre_doctor_5);
        rb_is_abnormal_no_2 = (RadioButton)child.findViewById(R.id.pre_is_abnormal_no_2);
        rb_is_abnormal_no_3 = (RadioButton)child.findViewById(R.id.pre_is_abnormal_no_3);
        rb_is_abnormal_no_4 = (RadioButton)child.findViewById(R.id.pre_is_abnormal_no_4);
        rb_is_abnormal_no_5 = (RadioButton)child.findViewById(R.id.pre_is_abnormal_no_5);
        rb_is_abnormal_yes_2 = (RadioButton)child.findViewById(R.id.pre_is_abnormal_yes_2);
        rb_is_abnormal_yes_3 = (RadioButton)child.findViewById(R.id.pre_is_abnormal_yes_3);
        rb_is_abnormal_yes_4 = (RadioButton)child.findViewById(R.id.pre_is_abnormal_yes_4);
        rb_is_abnormal_yes_5 = (RadioButton)child.findViewById(R.id.pre_is_abnormal_yes_5);
        rb_need_transfer_no_2 = (RadioButton)child.findViewById(R.id.pre_need_transfer_no_2);
        rb_need_transfer_no_3 = (RadioButton)child.findViewById(R.id.pre_need_transfer_no_3);
        rb_need_transfer_no_4 = (RadioButton)child.findViewById(R.id.pre_need_transfer_no_4);
        rb_need_transfer_no_5 = (RadioButton)child.findViewById(R.id.pre_need_transfer_no_5);
        rb_need_transfer_yes_2 = (RadioButton)child.findViewById(R.id.pre_need_transfer_yes_2);
        rb_need_transfer_yes_3 = (RadioButton)child.findViewById(R.id.pre_need_transfer_yes_3);
        rb_need_transfer_yes_4 = (RadioButton)child.findViewById(R.id.pre_need_transfer_yes_4);
        rb_need_transfer_yes_5 = (RadioButton)child.findViewById(R.id.pre_need_transfer_yes_5);
		cb_guide_2_1 = (CheckBox)child.findViewById(R.id.pre_guide_2_1);
		cb_guide_2_2 = (CheckBox)child.findViewById(R.id.pre_guide_2_2);
		cb_guide_2_3 = (CheckBox)child.findViewById(R.id.pre_guide_2_3);
		cb_guide_2_4 = (CheckBox)child.findViewById(R.id.pre_guide_2_4);
		cb_guide_2_5 = (CheckBox)child.findViewById(R.id.pre_guide_2_5);
		cb_guide_3_1 = (CheckBox)child.findViewById(R.id.pre_guide_3_1);
		cb_guide_3_2 = (CheckBox)child.findViewById(R.id.pre_guide_3_2);
		cb_guide_3_3 = (CheckBox)child.findViewById(R.id.pre_guide_3_3);
		cb_guide_3_4 = (CheckBox)child.findViewById(R.id.pre_guide_3_4);
        cb_guide_3_5 = (CheckBox)child.findViewById(R.id.pre_guide_3_5);
        cb_guide_3_6 = (CheckBox)child.findViewById(R.id.pre_guide_3_6);
        cb_guide_3_7 = (CheckBox)child.findViewById(R.id.pre_guide_3_7);
        cb_guide_4_1 = (CheckBox)child.findViewById(R.id.pre_guide_4_1);
        cb_guide_4_2 = (CheckBox)child.findViewById(R.id.pre_guide_4_2);
        cb_guide_4_3 = (CheckBox)child.findViewById(R.id.pre_guide_4_3);
        cb_guide_4_4 = (CheckBox)child.findViewById(R.id.pre_guide_4_4);
        cb_guide_4_5 = (CheckBox)child.findViewById(R.id.pre_guide_4_5);
        cb_guide_4_6 = (CheckBox)child.findViewById(R.id.pre_guide_4_6);
        cb_guide_4_7 = (CheckBox)child.findViewById(R.id.pre_guide_4_7);
        cb_guide_4_8 = (CheckBox)child.findViewById(R.id.pre_guide_4_8);
        cb_guide_5_1 = (CheckBox)child.findViewById(R.id.pre_guide_5_1);
        cb_guide_5_2 = (CheckBox)child.findViewById(R.id.pre_guide_5_2);
        cb_guide_5_3 = (CheckBox)child.findViewById(R.id.pre_guide_5_3);
        cb_guide_5_4 = (CheckBox)child.findViewById(R.id.pre_guide_5_4);
        cb_guide_5_5 = (CheckBox)child.findViewById(R.id.pre_guide_5_5);
        cb_guide_5_6 = (CheckBox)child.findViewById(R.id.pre_guide_5_6);
        cb_guide_5_7 = (CheckBox)child.findViewById(R.id.pre_guide_5_7);
        cb_guide_5_8 = (CheckBox)child.findViewById(R.id.pre_guide_5_8);
        rgIsAbnormal_2 = (RadioGroup)child.findViewById(R.id.RadioGroup11);
        rgIsAbnormal_3 = (RadioGroup)child.findViewById(R.id.RadioGroup10);
        rgIsAbnormal_4 = (RadioGroup)child.findViewById(R.id.RadioGroup09);
        rgIsAbnormal_5 = (RadioGroup)child.findViewById(R.id.RadioGroup08);
        rgNeedTransfer_2 = (RadioGroup)child.findViewById(R.id.RadioGroup13);
        rgNeedTransfer_3 = (RadioGroup)child.findViewById(R.id.RadioGroup01);
        rgNeedTransfer_4 = (RadioGroup)child.findViewById(R.id.RadioGroup02);
        rgNeedTransfer_5 = (RadioGroup)child.findViewById(R.id.RadioGroup03);
	}

	/**
	 * 读取数据
	 */
	public void fetchData(){
		ht = new HereTipa(mContext);
		ht.selectNameAndCode(this.profileid);
		
		//先取出第二次的
		pv = new PrenatalVisit(mContext);
//		pv.setPrvi_id(this.profileid);
//		pv.setPrvi_times(2);
		pv.selectPrenatalVisit(this.profileid, 2);
		
	}
	
	/**
	 * 添加view到父view中
	 */
	public void setMyView(){
		LayoutParams lp = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
		this.addView(child,lp);
		
	}
	
	/**
	 * 将整个界面作为一个view对象
	 * @return 整个界面view
	 */
	public View getMyView(){
		return this.child;
	}
	
	/**
	 * 保存views的值至数据库
	 */
	public void saveViews(){
		String temp="";
		StringBuffer sb=null;
		
		PrenatalVisit pv = new PrenatalVisit(mContext);
		pv.setPrvi_id(this.profileid);
		
		//second time
		pv.setPrvi_times(2);
		pv.selectPrenatalVisit(profileid, 2);
		
		temp = et_date_2.getText().toString();
		pv.setPrvi_date(temp);
		temp = et_preg_week_2.getText().toString();
		if(temp.length()>0){
			pv.setPrvi_preg_week(Integer.parseInt(temp));
		}
		temp = et_selftalk_2.getText().toString();
		pv.setPrvi_selftalk(temp);
		temp = et_weight_2.getText().toString();
		if(temp.length()>0){
			pv.setPrvi_weight(Float.parseFloat(temp));
		}
		temp = et_palace_height_2.getText().toString();
		if(temp.length()>0){
			pv.setPrvi_palace_height(Integer.parseInt(temp));
		}
		temp = et_chest_measure_2.getText().toString();
		if(temp.length()>0){
			pv.setPrvi_chest_measure(Integer.parseInt(temp));
		}
		temp = et_fetal_position_2.getText().toString();
		pv.setPrvi_fetal_position(temp);
		temp = et_fetal_heartrate_2.getText().toString();
		if(temp.length()>0){
			pv.setPrvi_fetal_heartrate(Integer.parseInt(temp));
		}
		temp = et_bloodpressure_high_2.getText().toString();
		if(temp.length()>0){
			pv.setPrvi_bloodpressure_high(Integer.parseInt(temp));
		}
		temp = et_bloodpressure_low_2.getText().toString();
		if(temp.length()>0){
			pv.setPrvi_bloodpressure_low(Integer.parseInt(temp));
		}
		temp = et_hgb_2.getText().toString();
		if(temp.length()>0){
			pv.setPrvi_hgb(Float.parseFloat(temp));
		}
		temp = et_urine_protein_2.getText().toString();
		if(temp.length()>0){
			pv.setPrvi_urine_protein(Float.parseFloat(temp));
		}
		temp = et_other_assitest_2.getText().toString();
		pv.setPrvi_other_assitest(temp);
		
		if(rb_is_abnormal_no_2.isChecked()==true){
			pv.setPrvi_is_abnormal(1);
		}else if(rb_is_abnormal_yes_2.isChecked()==true){
			pv.setPrvi_is_abnormal(2);
			temp = et_abnormal_2.getText().toString();
			pv.setPrvi_abnormal(temp);
		}
		
		sb = new StringBuffer();
		if(cb_guide_2_1.isChecked()==true){
			sb.append("1,");
		}
		if(cb_guide_2_2.isChecked()==true){
			sb.append("2,");
		}
		if(cb_guide_2_3.isChecked()==true){
			sb.append("3,");
		}
		if(cb_guide_2_4.isChecked()==true){
			sb.append("4,");
		}
		if(cb_guide_2_5.isChecked()==true){
			sb.append("5,");
			temp = et_guide_2_other.getText().toString();
			pv.setPrvi_other_guide(temp);
		}
		pv.setPrvi_guide(sb.toString());
		
		if(rb_need_transfer_no_2.isChecked()==true){
			pv.setPrvi_need_transfer(1);
		}else if(rb_need_transfer_yes_2.isChecked()==true){
			pv.setPrvi_need_transfer(2);
			temp = et_transfer_reason_2.getText().toString();
			pv.setPrvi_transfer_reason(temp);
			temp = et_transfer_hospital_2.getText().toString();
			pv.setPrvi_transfer_hospital(temp);
		}
		temp = et_next_visit_date_2.getText().toString();
		pv.setPrvi_next_visit_date(temp);
		temp = et_doctor_2.getText().toString();
		pv.setPrvi_doctor(temp);
		
		pv.updatePrenatalVisit(this.profileid, 2);
		
		//third time
		pv.setPrvi_times(3);
		pv.selectPrenatalVisit(profileid, 3);

		temp = et_date_3.getText().toString();
		pv.setPrvi_date(temp);
		temp = et_preg_week_3.getText().toString();
		if(temp.length()>0){
			pv.setPrvi_preg_week(Integer.parseInt(temp));
		}
		temp = et_selftalk_3.getText().toString();
		pv.setPrvi_selftalk(temp);
		temp = et_weight_3.getText().toString();
		if(temp.length()>0){
			pv.setPrvi_weight(Float.parseFloat(temp));
		}
		temp = et_palace_height_3.getText().toString();
		if(temp.length()>0){
			pv.setPrvi_palace_height(Integer.parseInt(temp));
		}
		temp = et_chest_measure_3.getText().toString();
		if(temp.length()>0){
			pv.setPrvi_chest_measure(Integer.parseInt(temp));
		}
		temp = et_fetal_position_3.getText().toString();
		pv.setPrvi_fetal_position(temp);
		temp = et_fetal_heartrate_3.getText().toString();
		if(temp.length()>0){
			pv.setPrvi_fetal_heartrate(Integer.parseInt(temp));
		}
		temp = et_bloodpressure_high_3.getText().toString();
		if(temp.length()>0){
			pv.setPrvi_bloodpressure_high(Integer.parseInt(temp));
		}
		temp = et_bloodpressure_low_3.getText().toString();
		if(temp.length()>0){
			pv.setPrvi_bloodpressure_low(Integer.parseInt(temp));
		}
		temp = et_hgb_3.getText().toString();
		if(temp.length()>0){
			pv.setPrvi_hgb(Float.parseFloat(temp));
		}
		temp = et_urine_protein_3.getText().toString();
		if(temp.length()>0){
			pv.setPrvi_urine_protein(Float.parseFloat(temp));
		}
		temp = et_other_assitest_3.getText().toString();
		pv.setPrvi_other_assitest(temp);
		
		if(rb_is_abnormal_no_3.isChecked()==true){
			pv.setPrvi_is_abnormal(1);
		}else if(rb_is_abnormal_yes_3.isChecked()==true){
			pv.setPrvi_is_abnormal(2);
			temp = et_abnormal_3.getText().toString();
			pv.setPrvi_abnormal(temp);
		}
		
		sb = new StringBuffer();
		if(cb_guide_3_1.isChecked()==true){
			sb.append("1,");
		}
		if(cb_guide_3_2.isChecked()==true){
			sb.append("2,");
		}
		if(cb_guide_3_3.isChecked()==true){
			sb.append("3,");
		}
		if(cb_guide_3_4.isChecked()==true){
			sb.append("4,");
		}
		if(cb_guide_3_5.isChecked()==true){
			sb.append("5,");
		}
		if(cb_guide_3_6.isChecked()==true){
			sb.append("6,");
		}
		if(cb_guide_3_7.isChecked()==true){
			sb.append("7,");
			temp = et_guide_3_other.getText().toString();
			pv.setPrvi_other_guide(temp);
		}
		pv.setPrvi_guide(sb.toString());
		
		if(rb_need_transfer_no_3.isChecked()==true){
			pv.setPrvi_need_transfer(1);
		}else if(rb_need_transfer_yes_3.isChecked()==true){
			pv.setPrvi_need_transfer(2);
			temp = et_transfer_reason_3.getText().toString();
			pv.setPrvi_transfer_reason(temp);
			temp = et_transfer_hospital_3.getText().toString();
			pv.setPrvi_transfer_hospital(temp);
		}
		temp = et_next_visit_date_3.getText().toString();
		pv.setPrvi_next_visit_date(temp);
		temp = et_doctor_3.getText().toString();
		pv.setPrvi_doctor(temp);
		pv.updatePrenatalVisit(this.profileid, 3);
		
		//forth time
		pv.setPrvi_times(4);
		pv.selectPrenatalVisit(profileid, 4);

		temp = et_date_4.getText().toString();
		pv.setPrvi_date(temp);
		temp = et_preg_week_4.getText().toString();
		if(temp.length()>0){
			pv.setPrvi_preg_week(Integer.parseInt(temp));
		}
		temp = et_selftalk_4.getText().toString();
		pv.setPrvi_selftalk(temp);
		temp = et_weight_4.getText().toString();
		if(temp.length()>0){
			pv.setPrvi_weight(Float.parseFloat(temp));
		}
		temp = et_palace_height_4.getText().toString();
		if(temp.length()>0){
			pv.setPrvi_palace_height(Integer.parseInt(temp));
		}
		temp = et_chest_measure_4.getText().toString();
		if(temp.length()>0){
			pv.setPrvi_chest_measure(Integer.parseInt(temp));
		}
		temp = et_fetal_position_4.getText().toString();
		pv.setPrvi_fetal_position(temp);
		temp = et_fetal_heartrate_4.getText().toString();
		if(temp.length()>0){
			pv.setPrvi_fetal_heartrate(Integer.parseInt(temp));
		}
		temp = et_bloodpressure_high_4.getText().toString();
		if(temp.length()>0){
			pv.setPrvi_bloodpressure_high(Integer.parseInt(temp));
		}
		temp = et_bloodpressure_low_4.getText().toString();
		if(temp.length()>0){
			pv.setPrvi_bloodpressure_low(Integer.parseInt(temp));
		}
		temp = et_hgb_4.getText().toString();
		if(temp.length()>0){
			pv.setPrvi_hgb(Float.parseFloat(temp));
		}
		temp = et_urine_protein_4.getText().toString();
		if(temp.length()>0){
			pv.setPrvi_urine_protein(Float.parseFloat(temp));
		}
		temp = et_other_assitest_4.getText().toString();
		pv.setPrvi_other_assitest(temp);
		
		if(rb_is_abnormal_no_4.isChecked()==true){
			pv.setPrvi_is_abnormal(1);
		}else if(rb_is_abnormal_yes_4.isChecked()==true){
			pv.setPrvi_is_abnormal(2);
			temp = et_abnormal_4.getText().toString();
			pv.setPrvi_abnormal(temp);
		}
		
		sb = new StringBuffer();
		if(cb_guide_4_1.isChecked()==true){
			sb.append("1,");
		}
		if(cb_guide_4_2.isChecked()==true){
			sb.append("2,");
		}
		if(cb_guide_4_3.isChecked()==true){
			sb.append("3,");
		}
		if(cb_guide_4_4.isChecked()==true){
			sb.append("4,");
		}
		if(cb_guide_4_5.isChecked()==true){
			sb.append("5,");
		}
		if(cb_guide_4_6.isChecked()==true){
			sb.append("6,");
		}
		if(cb_guide_4_7.isChecked()==true){
			sb.append("7,");
		}
		if(cb_guide_4_8.isChecked()==true){
			sb.append("8,");
			temp = et_guide_4_other.getText().toString();
			pv.setPrvi_other_guide(temp);
		}
		pv.setPrvi_guide(sb.toString());
		
		if(rb_need_transfer_no_4.isChecked()==true){
			pv.setPrvi_need_transfer(1);
		}else if(rb_need_transfer_yes_4.isChecked()==true){
			pv.setPrvi_need_transfer(2);
			temp = et_transfer_reason_4.getText().toString();
			pv.setPrvi_transfer_reason(temp);
			temp = et_transfer_hospital_4.getText().toString();
			pv.setPrvi_transfer_hospital(temp);
		}
		temp = et_next_visit_date_4.getText().toString();
		pv.setPrvi_next_visit_date(temp);
		temp = et_doctor_4.getText().toString();
		pv.setPrvi_doctor(temp);
		pv.updatePrenatalVisit(this.profileid, 4);
		
		//fifth time
		pv.setPrvi_times(5);
		pv.selectPrenatalVisit(profileid, 5);

		temp = et_date_5.getText().toString();
		pv.setPrvi_date(temp);
		temp = et_preg_week_5.getText().toString();
		if(temp.length()>0){
			pv.setPrvi_preg_week(Integer.parseInt(temp));
		}
		temp = et_selftalk_5.getText().toString();
		pv.setPrvi_selftalk(temp);
		temp = et_weight_5.getText().toString();
		if(temp.length()>0){
			pv.setPrvi_weight(Float.parseFloat(temp));
		}
		temp = et_palace_height_5.getText().toString();
		if(temp.length()>0){
			pv.setPrvi_palace_height(Integer.parseInt(temp));
		}
		temp = et_chest_measure_5.getText().toString();
		if(temp.length()>0){
			pv.setPrvi_chest_measure(Integer.parseInt(temp));
		}
		temp = et_fetal_position_5.getText().toString();
		pv.setPrvi_fetal_position(temp);
		temp = et_fetal_heartrate_5.getText().toString();
		if(temp.length()>0){
			pv.setPrvi_fetal_heartrate(Integer.parseInt(temp));
		}
		temp = et_bloodpressure_high_5.getText().toString();
		if(temp.length()>0){
			pv.setPrvi_bloodpressure_high(Integer.parseInt(temp));
		}
		temp = et_bloodpressure_low_5.getText().toString();
		if(temp.length()>0){
			pv.setPrvi_bloodpressure_low(Integer.parseInt(temp));
		}
		temp = et_hgb_5.getText().toString();
		if(temp.length()>0){
			pv.setPrvi_hgb(Float.parseFloat(temp));
		}
		temp = et_urine_protein_5.getText().toString();
		if(temp.length()>0){
			pv.setPrvi_urine_protein(Float.parseFloat(temp));
		}
		temp = et_other_assitest_5.getText().toString();
		pv.setPrvi_other_assitest(temp);
		
		if(rb_is_abnormal_no_5.isChecked()==true){
			pv.setPrvi_is_abnormal(1);
		}else if(rb_is_abnormal_yes_5.isChecked()==true){
			pv.setPrvi_is_abnormal(2);
			temp = et_abnormal_5.getText().toString();
			pv.setPrvi_abnormal(temp);
		}
		
		sb = new StringBuffer();
		if(cb_guide_5_1.isChecked()==true){
			sb.append("1,");
		}
		if(cb_guide_5_2.isChecked()==true){
			sb.append("2,");
		}
		if(cb_guide_5_3.isChecked()==true){
			sb.append("3,");
		}
		if(cb_guide_5_4.isChecked()==true){
			sb.append("4,");
		}
		if(cb_guide_5_5.isChecked()==true){
			sb.append("5,");
		}
		if(cb_guide_5_6.isChecked()==true){
			sb.append("6,");
		}
		if(cb_guide_5_7.isChecked()==true){
			sb.append("7,");
		}
		if(cb_guide_5_8.isChecked()==true){
			sb.append("8,");
			temp = et_guide_5_other.getText().toString();
			pv.setPrvi_other_guide(temp);
		}
		pv.setPrvi_guide(sb.toString());
		
		if(rb_need_transfer_no_5.isChecked()==true){
			pv.setPrvi_need_transfer(1);
		}else if(rb_need_transfer_yes_5.isChecked()==true){
			pv.setPrvi_need_transfer(2);
			temp = et_transfer_reason_5.getText().toString();
			pv.setPrvi_transfer_reason(temp);
			temp = et_transfer_hospital_5.getText().toString();
			pv.setPrvi_transfer_hospital(temp);
		}
		temp = et_next_visit_date_5.getText().toString();
		pv.setPrvi_next_visit_date(temp);
		temp = et_doctor_5.getText().toString();
		pv.setPrvi_doctor(temp);
		pv.updatePrenatalVisit(this.profileid, 5);
		
	}
	
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if(v==et_date_2){
			mPopupWindow = new MyPopupWindow(mContext);			
			mPopupWindow.showAtLocation(v.findViewById(R.id.pre_date_2), Gravity.CENTER, 0, 0);

			Button btn=mPopupWindow.getButton();
			btn.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					et_date_2.setText(mPopupWindow.getDate());
					mPopupWindow.dismiss();
				}
				
			});
		}
		else if(v==et_date_3){
			mPopupWindow = new MyPopupWindow(mContext);			
			mPopupWindow.showAtLocation(v.findViewById(R.id.pre_date_3), Gravity.CENTER, 0, 0);

			Button btn=mPopupWindow.getButton();
			btn.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					et_date_3.setText(mPopupWindow.getDate());
					mPopupWindow.dismiss();
				}
				
			});
		}
		else if(v==et_date_4){
			mPopupWindow = new MyPopupWindow(mContext);			
			mPopupWindow.showAtLocation(v.findViewById(R.id.pre_date_4), Gravity.CENTER, 0, 0);

			Button btn=mPopupWindow.getButton();
			btn.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					et_date_4.setText(mPopupWindow.getDate());
					mPopupWindow.dismiss();
				}
				
			});
		}
		else if(v==et_date_5){
			mPopupWindow = new MyPopupWindow(mContext);			
			mPopupWindow.showAtLocation(v.findViewById(R.id.pre_date_5), Gravity.CENTER, 0, 0);

			Button btn=mPopupWindow.getButton();
			btn.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					et_date_5.setText(mPopupWindow.getDate());
					mPopupWindow.dismiss();
				}
				
			});
		}
		else if(v==et_next_visit_date_2){
			mPopupWindow = new MyPopupWindow(mContext);			
			mPopupWindow.showAtLocation(v.findViewById(R.id.pre_next_visit_date_2), Gravity.CENTER, 0, 0);

			Button btn=mPopupWindow.getButton();
			btn.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					et_next_visit_date_2.setText(mPopupWindow.getDate());
					mPopupWindow.dismiss();
				}
				
			});
		}
		else if(v==et_next_visit_date_3){
			mPopupWindow = new MyPopupWindow(mContext);			
			mPopupWindow.showAtLocation(v.findViewById(R.id.pre_next_visit_date_3), Gravity.CENTER, 0, 0);

			Button btn=mPopupWindow.getButton();
			btn.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					et_next_visit_date_3.setText(mPopupWindow.getDate());
					mPopupWindow.dismiss();
				}
				
			});
		}
		else if(v==et_next_visit_date_4){
			mPopupWindow = new MyPopupWindow(mContext);			
			mPopupWindow.showAtLocation(v.findViewById(R.id.pre_next_visit_date_4), Gravity.CENTER, 0, 0);

			Button btn=mPopupWindow.getButton();
			btn.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					et_next_visit_date_4.setText(mPopupWindow.getDate());
					mPopupWindow.dismiss();
				}
				
			});
		}
		else if(v==et_next_visit_date_5){
			mPopupWindow = new MyPopupWindow(mContext);			
			mPopupWindow.showAtLocation(v.findViewById(R.id.pre_next_visit_date_5), Gravity.CENTER, 0, 0);

			Button btn=mPopupWindow.getButton();
			btn.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					et_next_visit_date_5.setText(mPopupWindow.getDate());
					mPopupWindow.dismiss();
				}
				
			});
		}
		else if(v==et_abnormal_2){
			rb_is_abnormal_no_2.setChecked(false);
			rb_is_abnormal_yes_2.setChecked(true);
		}
		else if(v==et_abnormal_3){
			rb_is_abnormal_no_3.setChecked(false);
			rb_is_abnormal_yes_3.setChecked(true);
		}
		else if(v==et_abnormal_4){
			rb_is_abnormal_no_4.setChecked(false);
			rb_is_abnormal_yes_4.setChecked(true);
		}
		else if(v==et_abnormal_5){
			rb_is_abnormal_no_5.setChecked(false);
			rb_is_abnormal_yes_5.setChecked(true);
		}
		else if(v==et_guide_2_other){
			cb_guide_2_5.setChecked(true);
		}
		else if(v==et_guide_3_other){
			cb_guide_3_7.setChecked(true);
		}
		else if(v==et_guide_4_other){
			cb_guide_4_8.setChecked(true);
		}
		else if(v==et_guide_5_other){
			cb_guide_5_8.setChecked(true);
		}
		else if((v==et_transfer_reason_2||v==et_transfer_hospital_2)){
			rb_need_transfer_no_2.setChecked(false);
			rb_need_transfer_yes_2.setChecked(true);
		}
		else if((v==et_transfer_reason_3||v==et_transfer_hospital_3)){
			rb_need_transfer_no_3.setChecked(false);
			rb_need_transfer_yes_3.setChecked(true);
		}
		else if((v==et_transfer_reason_4||v==et_transfer_hospital_4)){
			rb_need_transfer_no_4.setChecked(false);
			rb_need_transfer_yes_4.setChecked(true);
		}
		else if((v==et_transfer_reason_5||v==et_transfer_hospital_5)){
			rb_need_transfer_no_5.setChecked(false);
			rb_need_transfer_yes_5.setChecked(true);
		}
		
	}

	@Override
	public void onFocusChange(View v, boolean hasFocus) {
		// TODO Auto-generated method stub
		if(v==et_abnormal_2&&hasFocus){
			rb_is_abnormal_no_2.setChecked(false);
			rb_is_abnormal_yes_2.setChecked(true);
		}
		else if(v==et_abnormal_3&&hasFocus){
			rb_is_abnormal_no_3.setChecked(false);
			rb_is_abnormal_yes_3.setChecked(true);
		}
		else if(v==et_abnormal_4&&hasFocus){
			rb_is_abnormal_no_4.setChecked(false);
			rb_is_abnormal_yes_4.setChecked(true);
		}
		else if(v==et_abnormal_5&&hasFocus){
			rb_is_abnormal_no_5.setChecked(false);
			rb_is_abnormal_yes_5.setChecked(true);
		}
		else if(v==et_guide_2_other&&hasFocus){
			cb_guide_2_5.setChecked(true);
		}
		else if(v==et_guide_3_other&&hasFocus){
			cb_guide_3_7.setChecked(true);
		}
		else if(v==et_guide_4_other&&hasFocus){
			cb_guide_4_8.setChecked(true);
		}
		else if(v==et_guide_5_other&&hasFocus){
			cb_guide_5_8.setChecked(true);
		}
		else if((v==et_transfer_reason_2||v==et_transfer_hospital_2)&&hasFocus){
			rb_need_transfer_no_2.setChecked(false);
			rb_need_transfer_yes_2.setChecked(true);
		}
		else if((v==et_transfer_reason_3||v==et_transfer_hospital_3)&&hasFocus){
			rb_need_transfer_no_3.setChecked(false);
			rb_need_transfer_yes_3.setChecked(true);
		}
		else if((v==et_transfer_reason_4||v==et_transfer_hospital_4)&&hasFocus){
			rb_need_transfer_no_4.setChecked(false);
			rb_need_transfer_yes_4.setChecked(true);
		}
		else if((v==et_transfer_reason_5||v==et_transfer_hospital_5)&&hasFocus){
			rb_need_transfer_no_5.setChecked(false);
			rb_need_transfer_yes_5.setChecked(true);
		}
		else if(v==et_date_2&&hasFocus){
			mPopupWindow = new MyPopupWindow(getContext());			
			mPopupWindow.showAtLocation(v.findViewById(R.id.pre_date_2  ), Gravity.CENTER, 0, 0);

			Button btn=mPopupWindow.getButton();
			btn.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					et_date_2.setText(mPopupWindow.getDate());
					mPopupWindow.dismiss();
				}
				
			});
		}
		else if(v==et_date_3&&hasFocus){
			mPopupWindow = new MyPopupWindow(getContext());			
			mPopupWindow.showAtLocation(v.findViewById(R.id.pre_date_3  ), Gravity.CENTER, 0, 0);

			Button btn=mPopupWindow.getButton();
			btn.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					et_date_3.setText(mPopupWindow.getDate());
					mPopupWindow.dismiss();
				}
				
			});
		}
		else if(v==et_date_4&&hasFocus){
			mPopupWindow = new MyPopupWindow(getContext());			
			mPopupWindow.showAtLocation(v.findViewById(R.id.pre_date_4  ), Gravity.CENTER, 0, 0);

			Button btn=mPopupWindow.getButton();
			btn.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					et_date_4.setText(mPopupWindow.getDate());
					mPopupWindow.dismiss();
				}
				
			});
		}
		else if(v==et_date_5&&hasFocus){
			mPopupWindow = new MyPopupWindow(getContext());			
			mPopupWindow.showAtLocation(v.findViewById(R.id.pre_date_5  ), Gravity.CENTER, 0, 0);

			Button btn=mPopupWindow.getButton();
			btn.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					et_date_5.setText(mPopupWindow.getDate());
					mPopupWindow.dismiss();
				}
				
			});
		}
		else if(v==et_next_visit_date_2&&hasFocus){
			mPopupWindow = new MyPopupWindow(getContext());			
			mPopupWindow.showAtLocation(v.findViewById(R.id.pre_next_visit_date_2  ), Gravity.CENTER, 0, 0);

			Button btn=mPopupWindow.getButton();
			btn.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					et_next_visit_date_2.setText(mPopupWindow.getDate());
					mPopupWindow.dismiss();
				}
				
			});
		}
		else if(v==et_next_visit_date_3&&hasFocus){
			mPopupWindow = new MyPopupWindow(getContext());			
			mPopupWindow.showAtLocation(v.findViewById(R.id.pre_next_visit_date_3  ), Gravity.CENTER, 0, 0);

			Button btn=mPopupWindow.getButton();
			btn.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					et_next_visit_date_3.setText(mPopupWindow.getDate());
					mPopupWindow.dismiss();
				}
				
			});
		}
		else if(v==et_next_visit_date_4&&hasFocus){
			mPopupWindow = new MyPopupWindow(getContext());			
			mPopupWindow.showAtLocation(v.findViewById(R.id.pre_next_visit_date_4  ), Gravity.CENTER, 0, 0);

			Button btn=mPopupWindow.getButton();
			btn.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					et_next_visit_date_4.setText(mPopupWindow.getDate());
					mPopupWindow.dismiss();
				}
				
			});
		}
		else if(v==et_next_visit_date_5&&hasFocus){
			mPopupWindow = new MyPopupWindow(getContext());			
			mPopupWindow.showAtLocation(v.findViewById(R.id.pre_next_visit_date_5  ), Gravity.CENTER, 0, 0);

			Button btn=mPopupWindow.getButton();
			btn.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					et_next_visit_date_5.setText(mPopupWindow.getDate());
					mPopupWindow.dismiss();
				}				
			});
		}
	}
}
